package com.example.module_filemanage.MVVM.Module.QiNiu;

import android.os.AsyncTask;

import com.example.module_filemanage.Interface.ICallBack;
import com.example.module_filemanage.MVVM.Module.Business.TranModule;
import com.example.module_filemanage.MVVM.Module.Entil.Item_FileInfo_module;
import com.qiniu.storage.BucketManager;
import com.qiniu.storage.model.FileInfo;

import java.util.ArrayList;
import java.util.List;


/**
 * Created by SJ on 2018/4/19.
 */

public class GetFileInfo extends AsyncTask<String,List<Item_FileInfo_module>,Boolean> {
    private ICallBack mICallBack;
    public GetFileInfo(ICallBack callback) {
        mICallBack=callback;
    }

    @Override
    protected Boolean doInBackground(String... IStrings) {
        List<FileInfo> _list=new ArrayList<>();
        BucketManager.FileListIterator fileListIterator = ConfigManager.getInstance().getBucketManager().createFileListIterator(IStrings[0], "");
        while (fileListIterator.hasNext()) {
            //处理获取的file list结果
            FileInfo[] items = fileListIterator.next();
            for (FileInfo item : items) {
                _list.add(item);
//                    System.out.println(item.key);
//                    System.out.println(item.hash);
//                    System.out.println(item.fsize);
//                    System.out.println(item.mimeType);
//                    System.out.println(item.putTime);
//                    System.out.println(item.endUser);
               // Log.e(TAG, "doInBackground: "+item.key );
            }
        }
        publishProgress(TranModule.item_fileinfo(_list,IStrings[0]));

        return true;
    }
    @Override
    protected void onProgressUpdate(List<Item_FileInfo_module>[] values) {
        super.onProgressUpdate(values);
        mICallBack.success(values[0]);
    }

    @Override
    protected void onPostExecute(Boolean IBoolean) {
        super.onPostExecute(IBoolean);
    }
}
